package com.h2wallet.newsapi.modular.news.controller;

import com.h2wallet.newsapi.modular.news.service.ArticleService;
import com.h2wallet.newsapi.modular.news.vo.Article;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Slf4j
@Api(description = "文章分类API")
@RestController
@RequestMapping(value = "/article-types", produces = MediaType.APPLICATION_JSON_VALUE)
public class ArticleTypeController {

    @Resource
    private ArticleService articleService;



    @ApiOperation(value = "获取文章分类的文章")
    @GetMapping(value = "/{id}/articles")
    public List<Article> get(@PathVariable("id") int id,
                             @ApiParam("页码，从0开始")@RequestParam(required = false, defaultValue = "0") int page,
                             @ApiParam("页大小")@RequestParam(required = false, defaultValue = "10") int size,
                             HttpServletResponse response) {

        response.setHeader("Total", String.valueOf(articleService.countByTypeId(id)));
        return articleService.findAllByTypeId(id, page, size);
    }


}
